var app = getApp();
var com = require('../../common.js');
Page({
  data: {
    avtive: 0,
    list: [],
    index: 0
  },
  onLoad: function(options) {

    var _this = this
    _this.onShopList()
  },
  onInfo(e, v) {
    var _this = this
    wx.showToast({
      title: '加载中',
      icon: 'loading'
    })
    com.link(app.link.onShopTonover + v + '.st', {
      tag: e
    }, function(res) {
      console.log(res);
      _this.setData({
        info: res.data.response.turnover
      })
      wx.hideToast()
    }, "GET")
  },
  onShopList() {
    var _this = this,
      list = _this.data.list
    com.link(app.link.gropshop, {}, function(res) {
      console.log(res);
      res.data.data.map((v, k) => {
        list.push({
          title: res.data.data[k].supplier.title,
          id: res.data.data[k].id
        })
      })
      _this.setData({
        list: list
      })
      _this.onInfo('', res.data.data[0].id)
    }, "GET")
  },
  onReady: function() {},
  onShow: function() {},
  onHide: function() {},
  onUnload: function() {},
  onPullDownRefresh: function() {},
  onReachBottom: function() {},
  onShareAppMessage: function() {},
  onPicker(e) {
    console.log(e)
    var _this = this
    _this.setData({
      index: e.detail.value,
      avtive: 0
    })
    _this.onInfo('', _this.data.list[_this.data.index].id)
  },
  tap(e) {
    var _this = this,
      id = e.currentTarget.id
    _this.setData({
      avtive: id
    })
    _this.onInfo(e.currentTarget.dataset.type, _this.data.list[_this.data.index].id)
  }
})